package ch.pizzapp.kurier.view;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import ch.pizzapp.kurier.R;
import ch.pizzapp.kurier.data.PlaceData;

/**
 * Shanuka @Cyberlmj 3:08:30 PM Email: shanuka.gayashan@cyberlmj.com
 */
@EViewGroup(R.layout.place_list_item)
public class PlaceListItem extends LinearLayout {

	@ViewById(R.id.place)
	TextView place;

	@ViewById(R.id.minimumOrder)
	TextView minimumOrder;

	@ViewById(R.id.deliveryTime)
	TextView deliveryTime;

	@ViewById(R.id.zipcode)
	TextView zipcode;

	@ViewById(R.id.radioButton)
	CheckBox checkbox;
	
	public interface Callback {
		void clickPlace(PlaceData placeDataItem);

	}

	Callback mCallback;

	public void setOnCallback(Callback mCallback) {
		this.mCallback = mCallback;
	}

	public PlaceListItem(final Context context) {
		super(context);

	}

	public PlaceListItem(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public void bind(final PlaceData placeDataItem) {

		zipcode.setText(placeDataItem.getZip());

		minimumOrder.setText("minimim order: " + placeDataItem.getMinorder()
				+ " " + getResources().getString(R.string.crurncey));

		place.setText(placeDataItem.getTitle());

		deliveryTime.setText("delevery time: ca."
				+ placeDataItem.getOrdertime());

		checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {

				if (isChecked) {
					placeDataItem.setIsSelect(true);
					if (mCallback != null){
						mCallback.clickPlace(placeDataItem);
					}
					
				} else {
					placeDataItem.setIsSelect(false);
				}
			}
		});

	}
}
